add spec for website unzip

stvnrlly 10 ans auparavant
Parent
Commettre
795050636f
1 fichiers modifiés avec 32 ajouts et 0 suppressions
  1. 32 0
      spec/models/agents/website_agent_spec.rb

+ 32 - 0
spec/models/agents/website_agent_spec.rb

@@ -152,6 +152,38 @@ describe Agents::WebsiteAgent do
152 152
       end
153 153
     end
154 154
 
155
+    describe 'unzipping' do
156
+      it 'should unzip with unzip option' do
157
+        json = {
158
+          'response' => {
159
+            'version' => 2,
160
+            'title' => "hello!"
161
+          }
162
+        }
163
+        zipped = ActiveSupport::Gzip.compress(json.to_json)
164
+        stub_request(:any, /gzip/).to_return(:body => zipped, :status => 200)
165
+        site = {
166
+          'name' => "Some JSON Response",
167
+          'expected_update_period_in_days' => "2",
168
+          'type' => "json",
169
+          'url' => "http://gzip.com",
170
+          'mode' => 'on_change',
171
+          'extract' => {
172
+            'version' => { 'path' => 'response.version' },
173
+          },
174
+          'unzip' => 'gzip',
175
+        }
176
+        checker = Agents::WebsiteAgent.new(:name => "Weather Site", :options => site)
177
+        checker.user = users(:bob)
178
+        checker.save!
179
+
180
+        checker.check
181
+        event = Event.last
182
+        puts event.payload
183
+        expect(event.payload['version']).to eq(2)
184
+      end
185
+    end
186
+
155 187
     describe 'encoding' do
156 188
       it 'should be forced with force_encoding option' do
157 189
         huginn = "\u{601d}\u{8003}"